package org.openfdtd.core3d;

import javax.media.j3d.Appearance;
import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.LineAttributes;
import javax.media.j3d.PolygonAttributes;
import javax.media.j3d.TransparencyAttributes;

/**
 *
 * @author Dórian C. Langbeck
 */
public class ObjectStyle {
    public static final ObjectStyle DEFAULT_STYLE;

    static {
        Appearance da = new Appearance();
        da.setColoringAttributes(new ColoringAttributes(
            0.2f, 0.2f, 0.2f,
            ColoringAttributes.FASTEST
        ));

        da.setTransparencyAttributes(new TransparencyAttributes(
            TransparencyAttributes.FASTEST,
            0.5f,
            TransparencyAttributes.BLEND_SRC_ALPHA,
            TransparencyAttributes.BLEND_SRC_ALPHA
        ));

        da.setLineAttributes(new LineAttributes(
            2,
            LineAttributes.PATTERN_SOLID,
            false
        ));

        da.setPolygonAttributes(new PolygonAttributes(
            PolygonAttributes.POLYGON_FILL,
            PolygonAttributes.CULL_NONE,
            0
        ));


        Appearance aa = new Appearance();
        aa.setColoringAttributes(new ColoringAttributes(
            0.4f, 0.4f, 0.4f,
            ColoringAttributes.FASTEST
        ));

        aa.setTransparencyAttributes(new TransparencyAttributes(
            TransparencyAttributes.FASTEST,
            0.5f,
            TransparencyAttributes.BLEND_SRC_ALPHA,
            TransparencyAttributes.BLEND_SRC_ALPHA
        ));

        aa.setLineAttributes(new LineAttributes(
            1,
            LineAttributes.PATTERN_SOLID,
            false
        ));
        
        aa.setPolygonAttributes(new PolygonAttributes(
            PolygonAttributes.POLYGON_FILL,
            PolygonAttributes.CULL_NONE,
            0
        ));


        Appearance sa = new Appearance();
        sa.setColoringAttributes(new ColoringAttributes(
            0.2f, 0.2f, 0.2f,
            ColoringAttributes.FASTEST
        ));

        sa.setTransparencyAttributes(new TransparencyAttributes(
            TransparencyAttributes.FASTEST,
            0.5f,
            TransparencyAttributes.BLEND_SRC_ALPHA,
            TransparencyAttributes.BLEND_SRC_ALPHA
        ));

        sa.setLineAttributes(new LineAttributes(
            1,
            LineAttributes.PATTERN_SOLID,
            false
        ));

        sa.setPolygonAttributes(new PolygonAttributes(
            PolygonAttributes.POLYGON_FILL,
            PolygonAttributes.CULL_NONE,
            0
        ));

        DEFAULT_STYLE = new ObjectStyle(aa, da, sa);
    }

    protected Appearance activeAppearance;
    protected Appearance defaultAppearance;
    protected Appearance selectedAppearance;

    private ObjectStyle(Appearance activeAppearance, Appearance defaultAppearance, Appearance selectedAppearance) {
        Util.enableWrite(activeAppearance);
        Util.enableWrite(defaultAppearance);
        Util.enableWrite(selectedAppearance);

        this.activeAppearance = activeAppearance;
        this.defaultAppearance = defaultAppearance;
        this.selectedAppearance = selectedAppearance;
    }

    Appearance getAppearance() {
        return defaultAppearance;
    }

    void setAppearance(Appearance defaultAppearance) {
        Util.enableWrite(defaultAppearance);
        this.defaultAppearance = defaultAppearance;
    }

    Appearance getActiveAppearance() {
        return activeAppearance;
    }

    void setActiveAppearance(Appearance selectionAppearance) {
        Util.enableWrite(selectionAppearance);
        this.activeAppearance = selectionAppearance;
    }

    Appearance getSelectedAppearance() {
        return selectedAppearance;
    }

    void setSelectedAppearance(Appearance selectedAppearance) {
        this.selectedAppearance = selectedAppearance;
    }
}
